1 /*
2  * Copyright (c) 2011-2012 - Mauro Carvalho Chehab
3  * Copyright (c) 2012 - Andre Roth <neolynx@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation version 2.1 of the License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18  *
19  */
20 
21 module libdvbv5_d.sdt;
22 
23 import core.sys.posix.unistd;
24 
25 import libdvbv5_d.descriptors: dvb_desc;
26 import libdvbv5_d.dvb_fe: dvb_v5_fe_parms;
27 import libdvbv5_d.header: dvb_table_header;
28 
29 extern (C):
30 
31 /**
32  * @file sdt.h
33  * @ingroup dvb_table
34  * @brief Provides the descriptors for SDT MPEG-TS table
35  * @copyright GNU Lesser General Public License version 2.1 (LGPLv2.1)
36  * @author Mauro Carvalho Chehab
37  * @author Andre Roth
38  *
39  * @par Relevant specs
40  * The table described herein is defined at:
41  * - ISO/IEC 13818-1
42  *
43  * @see http://www.etherguidesystems.com/Help/SDOs/dvb/syntax/tablesections/SDT.aspx
44  *
45  * @par Bug Report
46  * Please submit bug reports and patches to linux-media@vger.kernel.org
47  */
48 
49 /* ssize_t */
50 
51 /**
52  * @def DVB_TABLE_SDT
53  *	@brief SDT table ID
54  *	@ingroup dvb_table
55  * @def DVB_TABLE_SDT2
56  *	@brief SDT table ID (alternative table ID)
57  *	@ingroup dvb_table
58  * @def DVB_TABLE_SDT_PID
59  *	@brief SDT Program ID
60  *	@ingroup dvb_table
61  */
62 enum DVB_TABLE_SDT = 0x42;
63 enum DVB_TABLE_SDT2 = 0x46;
64 enum DVB_TABLE_SDT_PID = 0x0011;
65 
66 /**
67  * @struct dvb_table_sdt_service
68  * @brief MPEG-TS SDT service table
69  * @ingroup dvb_table
70  *
71  * @param service_id		service id
72  * @param EIT_present_following	EIT present following
73  * @param EIT_schedule		EIT schedule
74  * @param desc_length		desc length
75  * @param free_CA_mode		free CA mode
76  * @param running_status	running status
77  * @param descriptor		pointer to struct dvb_desc
78  * @param next			pointer to struct dvb_table_sdt_service
79  *
80  * This structure is used to store the original SDT service table,
81  * converting the integer fields to the CPU endianness.
82  *
83  * The undocumented parameters are used only internally by the API and/or
84  * are fields that are reserved. They shouldn't be used, as they may change
85  * on future API releases.
86  *
87  * Everything after dvb_table_sdt_service::descriptor (including it) won't
88  * be bit-mapped to the data parsed from the MPEG TS. So, metadata are added
89  * there.
90  */
91 struct dvb_table_sdt_service
92 {
93     import std.bitmanip : bitfields;
94     align (1):
95 
96     ushort service_id;
97 
98     mixin(bitfields!(
99         ubyte, "EIT_present_following", 1,
100         ubyte, "EIT_schedule", 1,
101         ubyte, "reserved", 6));
102 
103     union
104     {
105         align (1):
106 
107         ushort bitfield;
108 
109         struct
110         {
111             import std.bitmanip : bitfields;
112             align (1):
113 
114             mixin(bitfields!(
115                 ushort, "desc_length", 12,
116                 ushort, "free_CA_mode", 1,
117                 ushort, "running_status", 3));
118         }
119     }
120 
121     // struct dvb_desc;
122     dvb_desc* descriptor;
123     dvb_table_sdt_service* next;
124 }
125 
126 /**
127  * @struct dvb_table_sdt
128  * @brief MPEG-TS SDT table
129  * @ingroup dvb_table
130  *
131  * @param header	struct dvb_table_header content
132  * @param network_id	network id
133  * @param service	pointer to struct dvb_table_sdt_service
134  *
135  * This structure is used to store the original SDT table,
136  * converting the integer fields to the CPU endianness.
137  *
138  * The undocumented parameters are used only internally by the API and/or
139  * are fields that are reserved. They shouldn't be used, as they may change
140  * on future API releases.
141  *
142  * Everything after dvb_table_sdt::service (including it) won't be bit-mapped
143  * to the data parsed from the MPEG TS. So, metadata are added there.
144  */
145 struct dvb_table_sdt
146 {
147     align (1):
148 
149     dvb_table_header header;
150     ushort network_id;
151     ubyte reserved;
152     dvb_table_sdt_service* service;
153 }
154 
155 /**
156  * @brief Macro used to find services on a SDT table
157  * @ingroup dvb_table
158  *
159  * @param _service	service to seek
160  * @param _sdt		pointer to struct dvb_table_sdt_service
161  */
162 
163 // struct dvb_v5_fe_parms;
164 
165 /**
166  * @brief Initializes and parses SDT table
167  * @ingroup dvb_table
168  *
169  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
170  * @param buf buffer containing the SDT raw data
171  * @param buflen length of the buffer
172  * @param table pointer to struct dvb_table_sdt to be allocated and filled
173  *
174  * This function allocates a SDT table and fills the fields inside
175  * the struct. It also makes sure that all fields will follow the CPU
176  * endianness. Due to that, the content of the buffer may change.
177  *
178  * @return On success, it returns the size of the allocated struct.
179  *	   A negative value indicates an error.
180  */
181 ssize_t dvb_table_sdt_init (
182     dvb_v5_fe_parms* parms,
183     const(ubyte)* buf,
184     ssize_t buflen,
185     dvb_table_sdt** table);
186 
187 /**
188  * @brief Frees all data allocated by the SDT table parser
189  * @ingroup dvb_table
190  *
191  * @param table pointer to struct dvb_table_sdt to be freed
192  */
193 void dvb_table_sdt_free (dvb_table_sdt* table);
194 
195 /**
196  * @brief Prints the content of the SDT table
197  * @ingroup dvb_table
198  *
199  * @param parms	struct dvb_v5_fe_parms pointer to the opened device
200  * @param table pointer to struct dvb_table_sdt
201  */
202 void dvb_table_sdt_print (dvb_v5_fe_parms* parms, dvb_table_sdt* table);